import pandas as pd
from gypb.component import DDBUploader
from gypb.apps.performance_analysis import m17_excel_parser
from dash import register_page

register_page(__name__, name="数仓数据上传", order=7)

def m17_parser(raw_m17_df:pd.DataFrame)->pd.DataFrame:
    panel_m17_df = m17_excel_parser(raw_m17_df)
    m17_df = panel_m17_df.stack().reset_index(level=-1)
    m17_df.columns = ["attribute", "value"]
    return m17_df
    
m17_excel_uploader = DDBUploader(
    name="m17_upload",
    db_path="dfs://position_daily",
    table_name = "attr_double",
    key_cols=["datetime", "code", "object"],
    cache_dir=None,
    parser=m17_parser,
    header=1,
)

layout = m17_excel_uploader.layout